package com.hery.demo;

import org.apache.flink.api.common.functions.RichFilterFunction;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.FilterOperator;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;

public class ParametersDemo {
    public static void main1(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Integer> source = env.fromElements(1, 2, 3);

        Configuration config = new Configuration();
        config.setInteger("limit", 2);

        source.map(new RichMapFunction<Integer, Object>(){

            @Override
            public void open(Configuration parameters) throws Exception {
                super.open(parameters);
                StreamingRuntimeContext runtimeContext = (StreamingRuntimeContext) getRuntimeContext();

            }

            @Override
            public Object map(Integer value) throws Exception {
                return null;
            }
        }).setParallelism(5);

        env.execute("jobName");

    }
    public static void main(String[] args) throws Exception {

        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        DataSet<Integer> toFilter = env.fromElements(1, 2, 3);

        Configuration config = new Configuration();
        config.setInteger("limit", 2);

        FilterOperator<Integer> limit = toFilter.filter(new RichFilterFunction<Integer>() {
            private int limit;

            @Override
            public void open(Configuration parameters) throws Exception {
                limit = parameters.getInteger("limit", 0);
            }

            @Override
            public boolean filter(Integer value) throws Exception {
                return value > limit;
            }
        }).withParameters(config);
        limit.print();
        env.execute();

    }
}
